package com.example.demo.entity.vo;

import com.example.demo.entity.pojo.Card;
import com.example.demo.entity.pojo.LevelType;
import com.example.demo.entity.pojo.Student;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.*;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class StudentVo {
    //id
    private int id;
    //账号
    private String account;
    //性别
    private String sex;
    //年龄
    private int age;
    //学号
    private int gardeNumber;
    //姓名
    private String name;
    //状态
    private int state;
    //可借书籍类型和数量
    private Map<String,Integer> book = new HashMap<>();
    //卡的等级
    private String level;
    //卡的余额
    private double money;
    //卡的创建时间
    private String startTime;
    //卡的结束时间
    private String endTime;
    //卡的卡号
    private int cardNumber;
    //卡的id
    private int cardId;
    //可以借的书籍本数
    private int count;

    public StudentVo(Student student, List<LevelType> levelType, Card card){
        this.id = student.getId();
        this.account = student.getAccount();
        if (student.getSex() == 1){
            this.sex = "女";
        }
        if (student.getSex() == 0) {
            this.sex = "男";
        }
        this.age = student.getAge();
        this.gardeNumber = student.getGardeNumber();
        this.name = student.getName();
        //设置等级
        if (levelType.get(0).getLevelId() == 1){
            this.level = "青铜";
        }
        if (levelType.get(0).getLevelId() == 2){
            this.level = "白银";
        }
        //设置书籍类型
        for (LevelType type : levelType) {
            if (type.getTypeId() == 1){
                book.put("小说", type.getBorrowNumber());
            }
            if (type.getTypeId() == 2){
                book.put("经典",type.getBorrowNumber());
            }
            if (type.getTypeId() == 3){
                book.put("科学",type.getBorrowNumber());
            }
            if (type.getTypeId() == 4){
                book.put("言情",type.getBorrowNumber());
            }
        }
        this.money = card.getMoney();
//        DateFormat format = DateFormat.getDateInstance();
        SimpleDateFormat formatDate=new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
        this.startTime = formatDate.format(card.getCreateTime());
        this.endTime = formatDate.format(card.getOverdueTime());
        this.cardNumber = card.getNumber();
        this.cardId = student.getCardId();
        this.count = card.getCount();
    }
}
